package com.rtx.edi.platform.dash.error.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rtx.edi.model.error.po.ApiReceiptFinish;
import com.rtx.edi.model.response.EdiResponse;
import com.rtx.edi.platform.dash.error.service.PlApiReceiptFinishService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = {"入库单回传错误信息"})
@RestController
@RequestMapping("/v1/plApiReceiptFinishError")
public class PlApiReceiptFinishErrorController {

	@Autowired
	private PlApiReceiptFinishService plApiReceiptFinishService;

	@ApiOperation(value = "入库单回传错误信息列表", notes = "分页获取入库单回传错误信息")
	@PostMapping("qryApiReceiptFinishError")
	public EdiResponse qryApiReceiptFinishError(@RequestBody ApiReceiptFinish dto) {
		Page<ApiReceiptFinish> pageParam = new Page<>(dto.getPageNum(),dto.getPageSize());
		plApiReceiptFinishService.selectApiReceiptFinishErrorForList("ris_edi",pageParam, dto);
		return EdiResponse.success().data("page",pageParam);
	}

	@ApiOperation(value = "入库单回传错误信列表", notes = "根据id查询入库单回传错误信息")
	@PostMapping("qryApiReceiptFinishErrorById")
	public EdiResponse qryApiReceiptFinishErrorById(@RequestBody ApiReceiptFinish dto) {

		return EdiResponse.success().data("item",plApiReceiptFinishService.getById(dto.getSerialkey()));
	}

	@ApiOperation(value = "入库单回传重发", notes = "入库单回传重发")
	@PostMapping("resend")
	public EdiResponse resend(@RequestBody List<ApiReceiptFinish> list) {
		try {
			for (ApiReceiptFinish dto : list) {
				plApiReceiptFinishService.updApiReceiptFinish("ris_edi", dto);
			}

			return EdiResponse.success();
		} catch (Exception e) {
			return EdiResponse.failed().returnMgr(e.getMessage());
		}

	}

	@ApiOperation(value = "标记成功", notes = "标记成功")
	@PostMapping("marksucc")
	public EdiResponse markSuccReceiptFinishError(@RequestBody List<ApiReceiptFinish> list) {
		try {
			for (ApiReceiptFinish dto : list) {
				plApiReceiptFinishService.updateSuccess("ris_edi", dto);
			}
			return EdiResponse.success();
		} catch (Exception e) {
			return EdiResponse.failed().returnMgr(e.getMessage());
		}
	}
}
